home *** CD-ROM | disk | FTP | other *** search
/ Aminet 49 / Aminet 49 (2002)(GTI - Schatztruhe)[!][Jun 2002].iso / Aminet / util / misc / ReportPlus.lha / ReportPlus / source / f12.c < prev    next >
C/C++ Source or Header  |  2002-04-15  |  17KB  |  547 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <intuition/intuition.h>
  4. #include <intuition/gadgetclass.h>
  5. #include <workbench/icon.h>
  6. #include <workbench/workbench.h>
  7. #include <dos/dosextens.h>
  8.  
  9. #include "rp.h" // before icon protos
  10.  
  11. #include <clib/alib_protos.h>
  12. #include <clib/exec_protos.h>
  13. #include <clib/intuition_protos.h>
  14. #include <clib/icon_protos.h>
  15. #include <clib/dos_protos.h>
  16. #include <pragmas/icon_pragmas.h>
  17. #include <reaction/reaction.h>
  18. #include <gadgets/chooser.h>
  19. #include <pragmas/chooser_pragmas.h>
  20. #include <gadgets/string.h>
  21. #include <pragmas/string_pragmas.h>
  22. #include <gadgets/checkbox.h>
  23. #include <pragmas/checkbox_pragmas.h>
  24. #include <gadgets/layout.h>
  25. #include <pragmas/layout_pragmas.h>
  26. #include <gadgets/button.h>
  27. #include <pragmas/button_pragmas.h>
  28. #include <images/label.h>
  29. #include <pragmas/label_pragmas.h>
  30. #include <proto/label.h>
  31. #include <classes/window.h>
  32. #include <pragmas/window_pragmas.h>
  33.  
  34. #include <stdlib.h>
  35. #include <string.h>
  36.  
  37. AGLOBAL ABOOL              quit              = FALSE;
  38. AGLOBAL struct Gadget*     icon_gadgets[GIDS_12 + 1];
  39. AGLOBAL struct IconStruct  icon =
  40. {   TRUE, FALSE,
  41.     WBDRAWER, ""
  42. };
  43.  
  44. // from rp.c
  45. IMPORT Object*             WinObject[FUNCTIONS + 1];
  46. IMPORT TEXT                IOBuffer[LONGESTFIELD + 1];
  47. IMPORT SBYTE               page;
  48. IMPORT TEXT                asldir[VLONGFIELD + 1];
  49. IMPORT ULONG               signal;
  50. IMPORT struct Window*      MainWindowPtr;
  51. IMPORT struct Screen*      ScreenPtr;
  52. IMPORT struct SharedStruct shared;
  53. IMPORT struct Library     *ButtonBase,
  54.                           *CheckBoxBase,
  55.                           *ChooserBase,
  56.                           *IconBase,
  57.                           *LabelBase,
  58.                           *LayoutBase,
  59.                           *StringBase,
  60.                           *WindowBase;
  61. IMPORT struct Menu*        MenuPtr;
  62. IMPORT ABOOL               done;
  63. IMPORT TEXT                aslresult[VLONGFIELD + 1];
  64.  
  65. #define ICONOPTIONS        8
  66.  
  67. MODULE ABOOL               stop;
  68. MODULE STRPTR IconOptions[ICONOPTIONS] =
  69. {   "Disk",
  70.     "Drawer",
  71.     "Tool",
  72.     "Project",
  73.     "Trashcan",
  74.     "Device",
  75.     "Kickstart",
  76.     "AppIcon"
  77. };
  78. /* icon.type is the same as the values used by the system. So, the
  79. value used by the gadget is one less than the actual value. */
  80.  
  81. AGLOBAL void icon1(void)
  82. {   ULONG               i;
  83.     struct List         ChooserList;
  84.     struct ChooserNode *ChooserNodePtr[7 + 1];
  85.     struct Hook         Hook12Struct;
  86.  
  87.     icon.pathname[0] = 0;
  88.  
  89.     NewList(&ChooserList);
  90.     for (i = 0; i <= 7; i++)
  91.     {   if (!(ChooserNodePtr[i] = (struct ChooserNode *) AllocChooserNode(CNA_Text, IconOptions[i], TAG_DONE)))
  92.         {   rq("Can't allocate chooser node!");
  93.         }
  94.         AddTail(&ChooserList, (struct Node *) ChooserNodePtr[i]);
  95.     } // automatically freed by ReAction at DisposeObject() time
  96.  
  97.     /* Create the window object. */
  98.     lockscreen();
  99.     gadtools();
  100.     InitHook(&Hook12Struct, Hook12Func, NULL);
  101.  
  102.     if (!(WinObject[12] =         NewObject(WINDOW_GetClass(), NULL,
  103.     // window
  104.     WA_PubScreen,                 ScreenPtr,
  105.     WA_ScreenTitle,               "Report+",
  106.     WA_Title,                     "Report+: Icon Processor",
  107.     WA_Activate,                  TRUE,
  108.     WA_DepthGadget,               TRUE,
  109.     WA_DragBar,                   TRUE,
  110.     WA_CloseGadget,               TRUE,
  111.     WA_SizeGadget,                TRUE,
  112.     WA_IDCMP,                     IDCMP_RAWKEY,
  113.     WINDOW_IDCMPHook,             &Hook12Struct,
  114.     WINDOW_IDCMPHookBits,         IDCMP_RAWKEY,
  115.     WINDOW_MenuStrip,             MenuPtr,
  116.     WINDOW_Position,              WPOS_CENTERSCREEN,
  117.     WINDOW_ParentGroup,           icon_gadgets[GID_12_LY1] =
  118.                                   NewObject(LAYOUT_GetClass(), NULL,
  119.         // root-layout
  120.         LAYOUT_Orientation,       LAYOUT_ORIENT_VERT,
  121.         LAYOUT_SpaceOuter,        TRUE,
  122.         LAYOUT_DeferLayout,       TRUE,
  123.         LAYOUT_AddChild,          NewObject(LAYOUT_GetClass(), NULL,
  124.             // layout
  125.             LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  126.             LAYOUT_SpaceOuter,    TRUE,
  127.             LAYOUT_VertAlignment, LALIGN_CENTER,
  128.             LAYOUT_HorizAlignment,LALIGN_CENTER,
  129.             LAYOUT_BevelStyle,    BVS_NONE,
  130.             LAYOUT_AddChild,      icon_gadgets[GID_12_CB1] =
  131.                                   NewObject(CHECKBOX_GetClass(), NULL,
  132.                 GA_ID,                GID_12_CB1,
  133.                 GA_RelVerify,         TRUE,
  134.                 GA_Text,              "_Optimize colours?",
  135.                 GA_Selected,          (BOOL) icon.optimize,
  136.             TAG_END),
  137.             CHILD_WeightedHeight,     0,
  138.             LAYOUT_AddImage,          NewObject
  139.             (   LABEL_GetClass(),     NULL,
  140.                 LABEL_Text,           "",
  141.                 TAG_END
  142.             ),
  143.             CHILD_WeightedWidth,      100,
  144.             LAYOUT_AddImage,
  145.             NewObject
  146.             (   LABEL_GetClass(),     NULL,
  147.                 LABEL_Text,           "_Type:",
  148.                 LABEL_Justification,  LJ_LEFT,
  149.             TAG_END),
  150.             CHILD_WeightedWidth,      0,
  151.             LAYOUT_AddChild,          icon_gadgets[GID_12_CH1] =
  152.             NewObject
  153.             (   CHOOSER_GetClass(),   NULL,
  154.                 GA_ID,                GID_12_CH1,
  155.                 GA_RelVerify,         TRUE,
  156.                 CHOOSER_PopUp,        TRUE,
  157.                 CHOOSER_Labels,       &ChooserList,
  158.                 CHOOSER_Selected,     (WORD) (icon.type - 1),
  159.             TAG_END),
  160.             CHILD_WeightedWidth,      0,
  161.         TAG_END), 
  162.         CHILD_WeightedHeight,         0,
  163.         LAYOUT_AddChild,              icon_gadgets[GID_12_CB2] =
  164.                                       NewObject(CHECKBOX_GetClass(), NULL,
  165.                 // checkbox
  166.                 GA_ID,                GID_12_CB2,
  167.                 GA_RelVerify,         TRUE,
  168.                 GA_Text,              "Preserve p_lanar data?",
  169.                 GA_Selected,          (BOOL) icon.planar,
  170.                 TAG_END),
  171.             CHILD_WeightedHeight,     0,
  172.             LAYOUT_AddChild,          NewObject(LAYOUT_GetClass(), NULL,
  173.                 // layout
  174.                 LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  175.                 LAYOUT_SpaceOuter,    TRUE,
  176.                 LAYOUT_VertAlignment, LALIGN_CENTER,
  177.                 LAYOUT_HorizAlignment,LALIGN_CENTER,
  178.                 LAYOUT_BevelStyle,    BVS_FIELD,
  179.                 LAYOUT_AddImage,      NewObject(LABEL_GetClass(), NULL,
  180.                     // label
  181.                     LABEL_Text,       "_Pathname(s):",
  182.                     LABEL_Justification,LJ_LEFT,
  183.                     TAG_END),
  184.                 LAYOUT_AddChild,      icon_gadgets[GID_12_ST1] =
  185.                                       NewObject(STRING_GetClass(), NULL,
  186.                     // string        
  187.                     GA_ID,            GID_12_ST1,
  188.                     GA_RelVerify,     TRUE,
  189.                     STRINGA_TextVal,  icon.pathname,
  190.                     STRINGA_MinVisible,20,
  191.                     TAG_END),
  192.                 LAYOUT_AddChild,      icon_gadgets[GID_12_BU1] =
  193.                                       NewObject(NULL, "button.gadget",
  194.                     // button
  195.                     GA_ID,            GID_12_BU1,
  196.                     GA_RelVerify,     TRUE,
  197.                     BUTTON_AutoButton,BAG_POPFILE,
  198.                     TAG_END),
  199.                 CHILD_WeightedWidth,  0,
  200.                 TAG_END),
  201.             CHILD_WeightedHeight,     0,
  202.             LAYOUT_AddChild,          icon_gadgets[GID_12_ST2] =
  203.                                       NewObject(STRING_GetClass(), NULL,
  204.                 // string        
  205.                 GA_ReadOnly,          TRUE,
  206.                 GA_ID,                GID_12_ST2,
  207.                 STRINGA_TextVal,      "Ready.",
  208.                 TAG_END),
  209.             CHILD_WeightedHeight,     0,
  210.             LAYOUT_AddChild,          NewObject(LAYOUT_GetClass(), NULL,
  211.                 // layout
  212.                 LAYOUT_Orientation,   LAYOUT_ORIENT_HORIZ,
  213.                 LAYOUT_SpaceOuter,    TRUE,
  214.                 LAYOUT_VertAlignment, LALIGN_CENTER,
  215.                 LAYOUT_HorizAlignment,LALIGN_CENTER,
  216.                 LAYOUT_BevelStyle,    BVS_NONE,
  217.                 LAYOUT_AddChild,      icon_gadgets[GID_12_BU3] =
  218.                                       NewObject(NULL, "button.gadget",
  219.                     // button
  220.                     GA_ID,            GID_12_BU3,
  221.                     GA_RelVerify,     TRUE,
  222.                     GA_Text,          "Pro_cess",
  223.                 TAG_END),
  224.                 CHILD_WeightedWidth,  50,
  225.                 LAYOUT_AddChild,      icon_gadgets[GID_12_BU4] =
  226.                                       NewObject(NULL, "button.gadget",
  227.                     // button
  228.                     GA_ID,            GID_12_BU4,
  229.                     GA_RelVerify,     TRUE,
  230.                     GA_Text,          "Stop",
  231.                     GA_Disabled,      TRUE,
  232.                     TAG_END),
  233.                 CHILD_WeightedWidth,  50,
  234.                 TAG_END),
  235.             CHILD_WeightedHeight,     0,
  236.             TAG_END),
  237.     TAG_END)
  238.     ))
  239.     {   rq("Can't create ReAction objects!");
  240.     }
  241.     unlockscreen();
  242.     openwindow();
  243.     ActivateLayoutGadget(icon_gadgets[GID_12_LY1], MainWindowPtr, NULL, (Object) icon_gadgets[GID_12_ST1]);
  244.     loop();
  245.     closewindow();
  246.     if (quit)
  247.     {   cleanexit(EXIT_SUCCESS);
  248. }   }
  249.  
  250. AGLOBAL void icon_do(void)
  251. {   STRPTR stringptr;
  252.  
  253.     if (!(GetAttr
  254.     (   CHOOSER_Selected, icon_gadgets[GID_12_CH1], (ULONG *) &(icon.type)
  255.     )))
  256.     {   rq("Unsupported inquiry!"); // should never happen
  257.     }
  258.     icon.type++;
  259.  
  260.     if (!(GetAttr
  261.     (   STRINGA_TextVal, icon_gadgets[GID_12_ST1], (ULONG *) &stringptr
  262.     )))
  263.     {   rq("Unsupported inquiry!"); // should never happen
  264.     }
  265.     strcpy(icon.pathname, stringptr);
  266.  
  267.     if (!(GetAttr
  268.     (   GA_Selected, icon_gadgets[GID_12_CB1], (ULONG *) &(icon.optimize)
  269.     )))
  270.     {   rq("Unsupported inquiry!"); // should never happen
  271.     }
  272.     if (!(GetAttr
  273.     (   GA_Selected, icon_gadgets[GID_12_CB2], (ULONG *) &(icon.planar)
  274.     )))
  275.     {   rq("Unsupported inquiry!"); // should never happen
  276.     }
  277.  
  278.     SetGadgetAttrs
  279.     (   icon_gadgets[GID_12_CH1], MainWindowPtr, NULL,
  280.         GA_Disabled, TRUE,
  281.         TAG_END
  282.     );
  283.     SetGadgetAttrs
  284.     (   icon_gadgets[GID_12_CB1], MainWindowPtr, NULL,
  285.         GA_Disabled, TRUE,
  286.         TAG_END
  287.     );
  288.     SetGadgetAttrs
  289.     (   icon_gadgets[GID_12_CB2], MainWindowPtr, NULL,
  290.         GA_Disabled, TRUE,
  291.         TAG_END
  292.     );
  293.     SetGadgetAttrs
  294.     (   icon_gadgets[GID_12_ST1], MainWindowPtr, NULL,
  295.         GA_Disabled, TRUE,
  296.         TAG_END
  297.     );
  298.     SetGadgetAttrs
  299.     (   icon_gadgets[GID_12_BU1], MainWindowPtr, NULL,
  300.         GA_Disabled, TRUE,
  301.         TAG_END
  302.     );
  303.     SetGadgetAttrs
  304.     (   icon_gadgets[GID_12_BU3], MainWindowPtr, NULL,
  305.         GA_Disabled, TRUE,
  306.         TAG_END
  307.     );
  308.     SetGadgetAttrs
  309.     (   icon_gadgets[GID_12_BU4], MainWindowPtr, NULL,
  310.         GA_Disabled, FALSE,
  311.         TAG_END
  312.     );
  313.     SetAttrs
  314.     (   WinObject[12],
  315.         WA_BusyPointer, TRUE,
  316.         TAG_END
  317.     );
  318.                           
  319.     strcpy(shared.pathname, icon.pathname);
  320.     convert(TRUE);
  321.     strcpy(icon.pathname, shared.pathname);
  322.  
  323.     if (!stop)
  324.     {   SetGadgetAttrs
  325.         (   icon_gadgets[GID_12_ST2], MainWindowPtr, NULL,
  326.             STRINGA_TextVal, "All done.",
  327.             TAG_END
  328.         );
  329.     }
  330.     SetAttrs
  331.     (   WinObject[12],
  332.         WA_BusyPointer, FALSE,
  333.         TAG_END
  334.     );
  335.     SetGadgetAttrs
  336.     (   icon_gadgets[GID_12_CH1], MainWindowPtr, NULL,
  337.         GA_Disabled, FALSE,
  338.         TAG_END
  339.     );
  340.     SetGadgetAttrs
  341.     (   icon_gadgets[GID_12_CB1], MainWindowPtr, NULL,
  342.         GA_Disabled, FALSE,
  343.         TAG_END
  344.     );
  345.     SetGadgetAttrs
  346.     (   icon_gadgets[GID_12_CB2], MainWindowPtr, NULL,
  347.         GA_Disabled, FALSE,
  348.         TAG_END
  349.     );
  350.     SetGadgetAttrs
  351.     (   icon_gadgets[GID_12_ST1], MainWindowPtr, NULL,
  352.         GA_Disabled, FALSE,
  353.         TAG_END
  354.     );
  355.     SetGadgetAttrs
  356.     (   icon_gadgets[GID_12_BU1], MainWindowPtr, NULL,
  357.         GA_Disabled, FALSE,
  358.         TAG_END
  359.     );
  360.     SetGadgetAttrs
  361.     (   icon_gadgets[GID_12_BU3], MainWindowPtr, NULL,
  362.         GA_Disabled, FALSE,
  363.         TAG_END
  364.     );
  365.     SetGadgetAttrs
  366.     (   icon_gadgets[GID_12_BU4], MainWindowPtr, NULL,
  367.         GA_Disabled, TRUE,
  368.         TAG_END
  369.     );
  370. }
  371.  
  372. AGLOBAL void iconconvert(ABOOL gui)
  373. {   TEXT               saystring[LONGFIELD + 1];
  374.     ULONG              length = strlen(shared.thisfile);
  375.     struct DiskObject* IconPtr;
  376.  
  377.     if (length <= 5) // in case we get passed an empty string
  378.     {   return;
  379.     }
  380.     if (!stricmp(&(shared.thisfile[length - 5]), ".info"))
  381.     {   shared.thisfile[length - 5] = 0;
  382.     }
  383.    
  384.     strcpy(saystring, "Processing ");
  385.     strcat(saystring, shared.thisfile);
  386.     strcat(saystring, ".info...");
  387.     if (gui)
  388.     {   SetGadgetAttrs
  389.         (   icon_gadgets[GID_12_ST2], MainWindowPtr, NULL,
  390.             STRINGA_TextVal, saystring,
  391.             TAG_END
  392.         );
  393.     } else
  394.     {   Printf("%s", saystring);
  395.         Flush(Output());
  396.         saystring[0] = 0;
  397.     }
  398.  
  399.     if (IconPtr = GetIconTags(shared.thisfile, TAG_DONE))
  400.     {   IconPtr->do_Type = (UWORD) icon.type;
  401.         if (PutIconTags(shared.thisfile, IconPtr,
  402.             ICONPUTA_NotifyWorkbench,     TRUE,
  403.             ICONPUTA_DropPlanarIconImage, (BOOL) !icon.planar,
  404.             ICONPUTA_OptimizeImageSpace,  (BOOL) icon.optimize,
  405.             TAG_DONE
  406.         ))
  407.         {   strcat(saystring, "done.");
  408.         } else strcat(saystring, "failed to write!");
  409.         FreeDiskObject(IconPtr);
  410.     } else strcat(saystring, "failed to read!");
  411.  
  412.     if (gui)
  413.     {   SetGadgetAttrs
  414.         (   icon_gadgets[GID_12_ST2], MainWindowPtr, NULL,
  415.             STRINGA_TextVal, saystring,
  416.             TAG_END
  417.         );
  418.     } else
  419.     {   Printf("%s\n", saystring);
  420.     }
  421.  
  422.     checkabort(gui);
  423. }
  424.  
  425. AGLOBAL void icon_loop(ULONG gid)
  426. {   STRPTR stringptr;
  427.  
  428.     switch (gid)
  429.     {
  430.     case GID_12_CH1:
  431.         if (!(GetAttr
  432.         (   CHOOSER_Selected, icon_gadgets[GID_12_CH1], (ULONG *) &(icon.type)
  433.         )))
  434.         {   rq("Unsupported inquiry!"); // should never happen
  435.         }
  436.         icon.type++;
  437.     break;
  438.     case GID_12_ST1:
  439.         if (!(GetAttr
  440.         (   STRINGA_TextVal, icon_gadgets[GID_12_ST1], (ULONG *) &stringptr
  441.         )))
  442.         {   rq("Unsupported inquiry!"); // should never happen
  443.         }
  444.         strcpy(icon.pathname, stringptr);
  445.     break;
  446.     case GID_12_BU1:
  447.         strcpy(shared.pathname, icon.pathname);
  448.         multiasl("#?.info");
  449.         strcpy(icon.pathname, shared.pathname);
  450.         SetGadgetAttrs
  451.         (   icon_gadgets[GID_12_ST1], MainWindowPtr, NULL,
  452.             STRINGA_TextVal, icon.pathname,
  453.             TAG_END
  454.         );
  455.     break;
  456.     case GID_12_BU3:
  457.         icon_do();
  458.     break;
  459.     case GID_12_CB1:
  460.         if (!(GetAttr
  461.         (   GA_Selected, icon_gadgets[GID_12_CB1], (ULONG *) &(icon.optimize)
  462.         )))
  463.         {   rq("Unsupported inquiry!"); // should never happen
  464.         }
  465.     break;
  466.     case GID_12_CB2:
  467.         if (!(GetAttr
  468.         (   GA_Selected, icon_gadgets[GID_12_CB2], (ULONG *) &(icon.planar)
  469.         )))
  470.         {   rq("Unsupported inquiry!"); // should never happen
  471.         }
  472.     break;
  473.     default:
  474.     break;
  475. }   }
  476.  
  477. AGLOBAL ULONG Hook12Func(struct Hook *h, VOID *o, VOID *msg)
  478. {   /* "When the hook is called, the data argument points to the 
  479.     window object and message argument to the IntuiMessage." */
  480.  
  481.     UWORD code, qual;
  482.  
  483.     geta4(); // wait till here before doing anything
  484.  
  485.     code = ((struct IntuiMessage *) msg)->Code;
  486.     qual = ((struct IntuiMessage *) msg)->Qualifier;
  487.  
  488.     switch(code)
  489.     {
  490.     case SCAN_HELP:
  491.         helpabout();
  492.     break;
  493.     case SCAN_ESCAPE:
  494.         if ((qual & IEQUALIFIER_LSHIFT) || (qual & IEQUALIFIER_RSHIFT))
  495.         {   cleanexit(EXIT_SUCCESS);
  496.         } else page = 0;
  497.     break;
  498.     case SCAN_P:
  499.         ActivateLayoutGadget(icon_gadgets[GID_12_LY1], MainWindowPtr, NULL, (Object) icon_gadgets[GID_12_ST1]);
  500.     break;
  501.     case SCAN_T:
  502.         if ((qual & IEQUALIFIER_LSHIFT) || (qual & IEQUALIFIER_RSHIFT))
  503.         {   if (icon.type == 1)
  504.             {   icon.type = ICONOPTIONS;
  505.             } else icon.type--;
  506.         } else
  507.         {   if (icon.type == ICONOPTIONS)
  508.             {   icon.type = 1;
  509.             } else icon.type++;
  510.         }
  511.  
  512.         SetGadgetAttrs
  513.         (   icon_gadgets[GID_12_CH1], MainWindowPtr, NULL,
  514.             CHOOSER_Selected, icon.type - 1,
  515.             TAG_END
  516.         );
  517.     break;
  518.     case SCAN_PERIOD:
  519.         strcpy(shared.pathname, icon.pathname);
  520.         multiasl("#?.info");
  521.         strcpy(icon.pathname, shared.pathname);
  522.         SetGadgetAttrs
  523.         (   icon_gadgets[GID_12_ST1], MainWindowPtr, NULL,
  524.             STRINGA_TextVal, icon.pathname,
  525.             TAG_END
  526.         );
  527.     break;
  528.     default:
  529.     break;
  530.     }
  531.  
  532.     return(1);
  533. }
  534.  
  535. AGLOBAL void icon_die(void)
  536. {   IOBuffer[16] = (UBYTE) icon.type;
  537.     IOBuffer[17] = (UBYTE) icon.optimize;
  538.     IOBuffer[18] = (UBYTE) icon.planar;
  539. }
  540.  
  541. AGLOBAL void icon_config(void)
  542. {   icon.type     = (ULONG) IOBuffer[16];
  543.     icon.optimize = (ULONG) IOBuffer[17];
  544.     icon.planar   = (ULONG) IOBuffer[18];
  545. }
  546.  
  547.